﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Crm.Sdk;

namespace XrmLibrary.MsCrm4Adapter.Extensions
{
    public static class BusinessEntityCollectionExtensions
    {
        public static EntityCollection ToEntityCollection(this BusinessEntityCollection businessEntityCollection)
        {
            EntityCollection entityCollection = new EntityCollection
                                                    {
                                                        EntityName = businessEntityCollection.EntityName,
                                                        MoreRecords = businessEntityCollection.MoreRecords,
                                                        PagingCookie = businessEntityCollection.PagingCookie
                                                    };
            foreach(BusinessEntity businessEntity in businessEntityCollection.BusinessEntities)
            {
                DynamicEntity dynamicEntity = (DynamicEntity) businessEntity;
                entityCollection.Entities.Add(dynamicEntity.ToEntity());
            }
            return entityCollection;
        }
    }
}
